package edu.utwente.sem.hrs.model;

import java.util.Date;
import java.util.HashSet;

import edu.utwente.sem.hrs.model.Bed.BedType;

public class Reservering
{
  @SuppressWarnings("deprecation")
  public static void main(String[] args)
  {
    Persoon p = new Persoon("Henk", "+31612345678",
        "Tiemboektoelaan 23, AltStad, Land");
    GastRol g = new GastRol("43215678");
    p.addRol(g);

    Bed b1 = new Bed(BedType.EENPERSOONS);
    Bed b2 = new Bed(BedType.TWEEPERSOONS);
    HashSet<Bed> bedden = new HashSet<Bed>();
    bedden.add(b1);
    bedden.add(b2);

    Kamer k = new Kamer(2, 5, 125.0, false, bedden);

    Reservering r = new Reservering(g, k, new Date(2013, 1, 12), new Date(2013,
        1, 14));
    System.out.println(r);
  }

  private boolean checkedIn;
  private GastRol gast;
  private Kamer kamer;
  private Date van;

  private Date tot;

  public Reservering(GastRol gast, Kamer kamer, Date van, Date tot)
  {
    this.gast = gast;
    this.kamer = kamer;
    if (!van.after(tot))
    {
      this.van = van;
      this.tot = tot;
    }
    else
    {
      this.van = tot;
      this.tot = van;
    }
    this.checkedIn = false;
  }

  @Override
  public boolean equals(Object obj)
  {
    boolean r = true;
    if (obj instanceof Reservering)
    {
      Reservering x = (Reservering) obj;
      if (!x.getGast().equals(gast))
        r = false;
      else if (!x.getKamer().equals(kamer))
        r = false;
      else if (!x.getVan().equals(van))
        r = false;
      else if (!x.getTot().equals(tot))
        r = false;
      else if (!x.isCheckedIn() == checkedIn)
        r = false;
    }
    else
      r = false;
    return r;
  }

  public boolean isCheckedIn()
  {
    return checkedIn;
  }

  @Override
  public int hashCode()
  {
    int hash = gast.hashCode() + kamer.hashCode() + van.hashCode()
        + tot.hashCode();
    if (checkedIn)
      hash = hash + 1;
    return hash;
  }

  public GastRol getGast()
  {
    return gast;
  }

  public Kamer getKamer()
  {
    return kamer;
  }

  public Date getTot()
  {
    return tot;
  }

  public Date getVan()
  {
    return van;
  }

  @SuppressWarnings("deprecation")
  @Override
  public String toString()
  {
    String s = "Reservering [";
    s += "gast: " + gast.getPersoon().getNaam();
    s += ", kamer: " + kamer.getKamernummer();
    s += ", van: " + van.getDate() + "-" + (van.getMonth() + 1) + "-"
        + van.getYear();
    s += ", tot: " + tot.getDate() + "-" + (tot.getMonth() + 1) + "-"
        + tot.getYear();
    s += ", checkedIn: " + checkedIn;
    s += "]";
    return s;
  }

  public void checkIn()
  {
    this.checkedIn = true;
  }

  public void checkUit()
  {
    this.checkedIn = false;
  }

}
